package learning.spring.helloworld;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 实现了 InvocationHandler 接口的jdk动态代理handler
 */
public class LogHandler implements InvocationHandler {
    private final Hello source;

    public LogHandler(Hello source) {
        this.source = source;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before.................");
        try {
            return method.invoke(source, args);
        } finally {
            System.out.println("after................");
        }
    }

}
